<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>操作元素属性</title>
    <style>

    </style>
</head>

<body>
    <div class="box1">
        <img src="img/娜美.jpg" alt="">
    </div>
    <div class="box2">
        <img src="img/爱与恨德克萨斯.jpg" alt="">
    </div>
    <div class="box3">
        <img src="img/特雷西亚.jpg" alt="">
    </div>

    <div id="first"></div>
    <div id="second"></div>
    <div id="third"></div>

    <script>
        window.addEventListener('DOMContentLoaded', () => {

            const img1 = document.querySelector('.box1 img');
            const img2 = document.querySelector('.box2 img');
            const img3 = document.querySelector('.box3 img');


            const imgarr = [img1, img2, img3];


            function xipai(arr) {
                for (let i = arr.length - 1; i > 0; i--) {
                    const j = Math.floor(Math.random() * (i + 1));
                    [arr[i], arr[j]] = [arr[j], arr[i]];
                }
                return arr;
            }


            const tup = xipai([...imgArr]);


            document.querySelector('#first').appendChild(tup[0]);
            document.querySelector('#second').appendChild(tup[1]);
            document.querySelector('#third').appendChild(tup[2]);
        });
    </script>
</body>

</html>